﻿#region COPYRIGHT
//--------------------------------------------------------------------------------
// <copyright file="Skin.cs" company="starLiGHT Entertainment Studios">
//    Copyright (c) 2011 
//       Roland Rosenkranz (Glatzemann@email.de)
// </copyright>
// <license>
//   This file is part of starLiGHT.GUI.
//
//   It is released under the Microsoft Public License (Ms-PL).
//
//   You should have received a copy of the Microsoft Public License
//   along with starLiGHT.GUI. If not, see http://sle.codeplex.com/license.
//    
//   ADDITIONAL (commercial) LICENSES for starLiGHT.GUI are available on request.
// </license>
// <version>
// **************[ starLiGHT.Engine SVN ]**********************
// * $Rev::                       $:  Revision of last commit *
// * $Author::                    $:  Author of last commit   *
// * $Date::                      $:  Date of last commit     *
// ************************************************************
// </version>
//--------------------------------------------------------------------------------
#endregion

namespace starLiGHT.GUI
{
#region Using Statements
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using Microsoft.Xna.Framework.Graphics;
#endregion

    public class Skin : IEquatable<Skin>
    {
        #region Private Members
        private GuiManager manager;
        private List<string> fonts = new List<string>();
        private List<Imageset> imagesets = new List<Imageset>();
        private List<Layout> layouts = new List<Layout>();
        private string skinFileName;
        #endregion

        public Skin(GuiManager manager, string skinFileName)
        {
            this.manager = manager;
            this.skinFileName = skinFileName;
        }

        public GuiManager GuiManager
        {
            get
            {
                return this.manager;
            }
        }

        public SpriteFont DefaultFont
        {
            get
            {
                // todo: make it better
                return GuiManager.LoadContent<SpriteFont>(this.fonts[0]);
            }
        }

        public void AddFont(string fontName)
        {
            if (string.IsNullOrEmpty(fontName))
            {
                throw new ArgumentNullException("fontName", "Argument fontName is not allowed to be null or empty");
            }

            this.fonts.Add(fontName);
        }

        public void AddImageSet(Imageset imageSet)
        {
            if (imageSet == null)
            {
                throw new ArgumentNullException("imageSet");
            }

            this.imagesets.Add(imageSet);
        }

        public void AddLayout(Layout layout)
        {
            if (layout == null)
            {
                throw new ArgumentNullException("layout");
            }

            this.layouts.Add(layout);
        }

        public Image GetImageReference(string name)
        {
            foreach (Imageset imageSet in this.imagesets)
            {
                foreach (Image image in imageSet.Images)
                {
                    if (image.Name.Equals(name, StringComparison.InvariantCultureIgnoreCase))
                    {
                        return image;
                    }
                }
            }

            return null;
        }

        public Layout GetLayout(string name)
        {
            foreach (Layout l in this.layouts)
            {
                if (l.Name.Equals(name, StringComparison.InvariantCultureIgnoreCase))
                {
                    return l;
                }
            }

            return null;
        }

        public bool Equals(Skin other)
        {
            return this.skinFileName.Equals(other.skinFileName, StringComparison.InvariantCultureIgnoreCase);
        }
    }
}
